package com.zh.junit.dao.entity;

import jakarta.persistence.*;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 对应数据库表：book
 * @author ZH
 * @date 20:40 2021/11/16
 */
//表示 insert 值不为null的字段，如：insert into book (title,author) values (?, ?)
@DynamicInsert
//表示当字段值有变化时，才对该字段进行update
//注意：不会忽略null值的字段，所以要防止被null值覆盖db中的值
@DynamicUpdate
@Entity
@Table(name = "book")
@Data
public class BookEntity {
    private String title;
    private String author;
    private String press;
    private BigDecimal price;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY) //ID数据库自增
    private Long id;

    private LocalDateTime createTime;
    private LocalDateTime updateTime;
    private String creater;
    private String modifier;
    private Integer version;
    private boolean deleted;

    public BookEntity(){
        this.creater = "SYSTEM";
        this.modifier = "SYSTEM";
        this.version = 1;
    }
}

